package com.wewins.fota.bean.bo.excel.column;

import com.wewins.fota.bean.bo.excel.CellSource;
import com.wewins.fota.bean.bo.excel.Column;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.CellType;

@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class NumericColumn implements Column {
    private Object value;

    @Builder.Default
    private CellType cellType = CellType.NUMERIC;

    @Override
    public void fillCell(CellSource source) {
        Cell cell = source.getCell();
        if (this.value instanceof Integer) {
            cell.setCellValue((Integer) this.value);
        } else if (this.value instanceof Long) {
            cell.setCellValue((Long) this.value);
        } else if (this.value instanceof Float) {
            cell.setCellValue((Float) this.value);
        } else if (this.value instanceof Double) {
            cell.setCellValue((Double) this.value);
        } else {
            cell.setCellValue(-1);
        }
    }
}
